package concurrent;

import java.util.concurrent.Callable;
import java.util.concurrent.FutureTask;

/**
 * @description: TODO join(),ThreadLocal
 * @author: wzj
 * @create: 2019/3/14 13:33
 */
public class MoreThread {

    public static void main(String[] args) throws Exception {

        //join()
//        MyThread mt= new MyThread();
//        MyThread mt1= new MyThread();
//        mt.start();
//        mt.join();//mt执行完 mt1才会start
//        mt1.start();

//        new Thread(new MyRunnableThread()).start();

        Callable<String> mct=new MyCallableThread();
        FutureTask<String> futureTask=new FutureTask<>(mct);
        new Thread(futureTask).start();
        System.out.println("futureTask.get(): "+futureTask.get());
    }
}
class MyThread extends Thread{
    @Override
    public void run() {
        System.out.println("Thread "+Thread.currentThread().getName());
        try {
            Thread.sleep(2000);
        } catch (InterruptedException e) {
            e.printStackTrace();
        }
    }
}
class MyRunnableThread implements Runnable {
    @Override
    public void run() {
        System.out.println("Runnable "+Thread.currentThread().getName());
    }
}
class MyCallableThread implements Callable<String>{
    @Override
    public String call() throws Exception {
        System.out.println("Callable ");
        return "call()返回值";
    }
}